/**
 * Created by hc on 2016/7/12.
 */
(function (main) {
    var UserAdd = {};

    UserAdd.bindEvent = function(){
        $("#btn_addUser").click(function(){
            var condition = $("#basic_validate").serialize();
            condition += "&province_name=" + $("#ssl_province").find("option:selected").text();
            condition += "&city_name=" + $("#ssl_city").find("option:selected").text();
            condition += "&district_name=" + $("#ssl_district").find("option:selected").text();

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/user/saveorupdate',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                    if (data.IsSuccess == 0) {
                        alert(data.ErrorMsg);
                        return;
                    } else {
                        alert('操作成功');
                    }
                },
                error: function (e, err_name, err_text) {

                }
            });

        });
    }

    $(document).ready(function () {
        CommonPage.InitRegion();
        UserAdd.bindEvent();

        //设置省市区
        if($("#temp_province").val()){
            $('#ssl_province').val($("#temp_province").val());
            $('#ssl_province').trigger('change');
        }
        if($("#temp_city").val()){
            $('#ssl_city').val($("#temp_city").val());
            $('#ssl_city').trigger('change');
        }
        if($("#temp_district").val()){
            $('#ssl_district').val($("#temp_district").val());
            $('#ssl_district').trigger('change');
        }
    });
})(window);